package cn.ysym.dao;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import cn.ysym.model.Promotion;

/**
 * Created by Administrator on 2016/12/19 0019.
 */

public class PromotionDao extends DaoBase {

    public PromotionDao(Context context) {
        super(context);
    }

    public List<Promotion> query(String filterStr) {
        List<Promotion> ret = new ArrayList<>();
        List<String[]> objs;
        if (filterStr != null && filterStr.length() > 0)
            objs = this.query(Integer.MAX_VALUE, "select promotionId, promotionName, promotionNamePy from promotion where promotionName like '%" + filterStr + "%' or promotionNamePy like '%" + filterStr + "%' order by promotionName");
        else
            objs = this.query(Integer.MAX_VALUE, "select promotionId, promotionName, promotionNamePy from promotion order by promotionName");
        for (String[] row : objs) {
            Promotion promotion = new Promotion();
            promotion.setPromotionId(row[0]);
            promotion.setPromotionName(row[1]);
            promotion.setPromotionNamePy(row[2]);
            ret.add(promotion);
        }
        return ret;
    }

    public void insert(Promotion model) {
        this.execSql("insert into promotion(promotionId, promotionName, promotionNamePy) values(?, ?, ?)", model.getPromotionId(), model.getPromotionName(), model.getPromotionNamePy());
    }

    public void clearAll() {
        this.execSql("delete from promotion");
    }
}
